/*
Copyright 2012 Wieser Dietmar, Margit Mutschlechner.

This file is part of Multimedia Social Networking Platform.

Multimedia Social Networking Platform is free software: 
you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Multimedia Social Networking Platform is distributed
in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Multimedia Social Networking Platform.  
If not, see <http://www.gnu.org/licenses/>.
*/

//import qt binding
Importer.loadQtBinding("qt.core");

var START_SYNCH = "START_SYNCH";
var FINISHED_SYNCH = "SYNCH_DONE";
var fileName = ".msnp_amarok.conf"
var filePath = QDir.homePath()+"/"+fileName;
//open file
var file = new QFile(filePath);
//trying to open file
if (file.open(new QIODevice.OpenMode(QIODevice.ReadOnly))) {
	//read content
	var ts = new QTextStream(file);
	var content = ts.readAll();
	file.close();
	//if scan must be done
	if (content.indexOf(START_SYNCH) == 0) {
		var time1 = QTime.currentTime();
		var time2 = time1.addSecs(3);
		while(time1.operator_less(time2)){
			time1 = QTime.currentTime();
		}
		Amarok.Collection.scanCollection();
		// delete file contents
		var dFile = new QFile(filePath);
		// write notification for msnp application
		if (dFile.open(new QIODevice.OpenMode(QIODevice.WriteOnly
				| QIODevice.Truncate))) {
			var dts = new QTextStream(dFile);
			dts.writeString(FINISHED_SYNCH);
			dFile.close();
		}
		Amarok.alert("The whole collection has been refreshed. Please restart Amarok now.");
		Amarok.quitAmarok();
	}
}

//var returnValue = Amarok.alert(
//		"Would you like to rescan the entire collection?", "questionYesNo");
//if (returnValue == 3) {
//	// Amarok.Collection.scanCollectionChanges();
//	Amarok.Collection.scanCollection();
//}

/* OLD CODE */

// Importer.loadQtBinding("qt.script");
// Importer.loadQtBinding("qt.object");
// Importer.loadQtBinding("qt.xml");
// Importer.loadQtBinding("qt.network");
// Importer.loadQtBinding("qt.gui");
//
// //var myhost = new QHostAddress("localhost");
// var sock = new QTcpSocket(this);
// var port = 25
//
// sock.connectToHost("localhost", port.toUInt16() , QIODevice.ReadWrite);
//
// function MsnpClient() {
// this.connected = connected;
// new QTcpSocket(this)
// }
//
// function connected() {
//
// }
//
// function startMsnpClient() {
// msnpCl = new MsnpClient();
// }
